package com.sunwayhorizo.health.hl7.rim;

import com.sunwayhorizo.health.hl7.common.*;
import com.sunwayhorizo.health.hl7.datatypes.*;
import com.sunwayhorizo.health.hl7.factories.*;
import com.sunwayhorizo.health.hl7.persistent.*;
import java.io.*;
import java.sql.Timestamp;

import javax.persistence.*;
import static com.sunwayhorizo.health.hl7.vocabulary.EntityCdSetCode.*;

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("LIV")
public class LivingSubject extends Hl7Entity implements Serializable
{

    /*
     * public CE AdministrativeGenderCode; public CE NationalityCode; public TS
     * BirthTime; public BLDeceasedInd; public TS DeceasedTime; public BL
     * MultipleBirthInd; public INT MultipleBirthOrderNumber; public BL
     * OrganDonorInd;
     */

    /**
     * 
     */
    protected static final long serialVersionUID = 1L;


    public LivingSubject() throws Hl7Exception
    {
    }


    public LivingSubject(ReferenceModifier referencemodifier)
    {
        super(referencemodifier);
    }


    /**
     * 
     * @Title: setAdministrativeGenderCode
     * @Description: 根据ets服务中拿到的值对RimCoreEntyCdSets进行设置，主要是对性别进行设置
     * @param @param administrativeGenderCode CE类型，主要包含性别的各个属性
     * @firstAuthor jinzw
     * @firstTime 2010-11-22 下午07:54:46
     * @lastAuthor jinzw
     * @lastTime 2010-11-22 下午07:54:46
     */
    public void setAdministrativeGenderCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreEntyCdSets(ce, ADMINISTRATIVEGENDERCODE);
        }
        else
        {
            this.setLsAdminGenderCodeEtsId(ce.code().toString());
        }
    }


    public CE getAdministrativeGenderCode() throws Hl7Exception
    {
        if (null != this.getLsAdminGenderCodeEtsId() && this.getLsAdminGenderCodeEtsId().equals(ADMINISTRATIVEGENDERCODE.toString()))
        {
            for (RimCoreEntyCdSets entityCdSets : this.getEntyCdSetsList())
            {
                if (this.getLsAdminGenderCodeEtsId().equals(entityCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(entityCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getLsAdminGenderCodeEtsId());
        return null;
    }

    /**
     * 设置国籍信息
     * @param ce 国籍编码
     */
    public void setNationalityCode(CE ce)
    {
        if (null != ce && ce.codeSystemEnName() != null && ce.codeName() != null)
        {
            setRimCoreEntyCdSets(ce, NATIONALITYCODE);
        }
        else
        {
            this.setLsNationalityCodeEtsId(ce.code().toString());
        }
    }

    /**
     * 得到国籍编码
     * @return  CE
     * @throws Hl7Exception
     */
    public CE getNationalityCode() throws Hl7Exception
    {
        if (null != this.getLsNationalityCodeEtsId() &&this.getLsNationalityCodeEtsId().equals(NATIONALITYCODE.toString()))
        {
            for (RimCoreEntyCdSets entityCdSets : this.getEntyCdSetsList())
            {
                if (this.getLsNationalityCodeEtsId().equals(entityCdSets.getAttributeTypeCode()))
                {
                    return DataTypeUtil.getCE(entityCdSets);
                }
            }
        }
        else
            return DataTypeUtil.getCE(this.getLsNationalityCodeEtsId());
        return null;
    }


    // set birthTime
    public void setBirthTime(TS birthTime)
    {
        if (null == birthTime)
            return;
        this.setLsBirthDateTs(new Timestamp(birthTime.toDate().getTime()));
        this.setLsBirthDateTxt(birthTime.literal().toString());
    }


    public TS getBirthTime() throws Hl7Exception
    {
        if (this.getLsBirthDateTs() != null)
        {
            return DataTypeUtil.getTS(this.getLsBirthDateTs());
        }
        else
            return DataTypeUtil.getTS("");
    }


    public void setDeceasedInd(BL deceasedInd)
    {
        this.setLsDeceasedFlag(deceasedInd.toString());
    }


    public BL getDeceasedInd() throws Hl7Exception
    {
        return DataTypeUtil.getBL(this.getLsDeceasedFlag());
    }


    public void setDeceasedTime(TS deceasedTime)
    {
        this.setLsDeceasedDateTs(new Timestamp(deceasedTime.toDate().getTime()));
        this.setLsDeceasedDateTxt(deceasedTime.literal().toString());
    }


    public TS getDeceasedTime() throws Hl7Exception
    {
        return DataTypeUtil.getTS(this.getLsDeceasedDateTs());
    }


    public void setMultipleBirthInd(BL multipleBirthInd)
    {
        this.setLsMultipleBirthFlag(multipleBirthInd.toString());
    }


    public BL getMultipleBirthInd() throws Hl7Exception
    {
        return DataTypeUtil.getBL(this.getLsMultipleBirthFlag());
    }


    public void setMultipleBirthOrderNumber(INT multipleBirthOrderNumber)
    {
        this.setLsMultipleBirthOrderNum(multipleBirthOrderNumber.longValue());
    }


    public INT getMultipleBirthOrderNumber() throws Hl7Exception
    {
        return DataTypeUtil.getINT(this.getLsMultipleBirthOrderNum());
    }


    public void setOrganDonorInd(BL organDonorInd)
    {
        this.setLsOrganDonorFlag(organDonorInd.toString());
    }


    public BL getOrganDonorInd() throws Hl7Exception
    {
        return DataTypeUtil.getBL(this.getLsOrganDonorFlag());
    }

    /**
     * 
     * @Title: setLsNationalityCodeEtsID
     * @Description: 设置lsNationalityCodeEtsId属性值
     * @param @param lsNationalityCodeEtsId 国籍代码
     * @return void
     * @throws
     * @firstAuthor jinzw
     * @firstTime 2010-11-15 上午09:43:27
     * @lastAuthor jinzw
     * @lastTime 2010-11-15 上午09:43:27
     */

    /**
     * 性别 @ author jinzw
     * 
     * @date 2010-11-15
     */
    @Column(name = "LS_ADMIN_GENDER_CODE_ETS_ID")
    protected String lsAdminGenderCodeEtsId = ADMINISTRATIVEGENDERCODE.toString();

    /**
     * 对应中国需求的国籍代码
     * 
     * @author jinzw
     * @date 2010-11-15
     */
    @Column(name = "LS_NATIONALITY_CODE_ETS_ID")
    protected String lsNationalityCodeEtsId = NATIONALITYCODE.toString();

    @Column(name = "LS_BIRTH_DATE_TS")
    protected Timestamp lsBirthDateTs;
    @Column(name = "LS_BIRTH_DATE_TXT")
    protected String lsBirthDateTxt;
    @Column(name = "LS_DECEASED_DATE_TS")
    protected Timestamp lsDeceasedDateTs;
    @Column(name = "LS_DECEASED_DATE_TXT")
    protected String lsDeceasedDateTxt;
    @Column(name = "LS_DECEASED_FLAG")
    protected String lsDeceasedFlag;
    @Column(name = "LS_MULTIPLE_BIRTH_FLAG")
    protected String lsMultipleBirthFlag;
    @Column(name = "LS_MULTIPLE_BIRTH_ORDER_NUM")
    protected Long lsMultipleBirthOrderNum;
    @Column(name = "LS_ORGAN_DONOR_FLAG")
    protected String lsOrganDonorFlag;


    protected String getLsNationalityCodeEtsId()
    {
        return lsNationalityCodeEtsId;
    }


    protected void setLsNationalityCodeEtsId(String lsNationalityCodeEtsId)
    {
        this.lsNationalityCodeEtsId = lsNationalityCodeEtsId;
    }


    protected void setLsAdminGenderCodeEtsId(String lsAdminGenderCodeEtsId)
    {
        this.lsAdminGenderCodeEtsId = lsAdminGenderCodeEtsId;
    }


    protected String getLsAdminGenderCodeEtsId()
    {
        return lsAdminGenderCodeEtsId;
    }


    protected void setLsBirthDateTs(Timestamp lsBirthDateTs)
    {
        this.lsBirthDateTs = lsBirthDateTs;
    }


    protected Timestamp getLsBirthDateTs()
    {
        return lsBirthDateTs;
    }


    protected void setLsBirthDateTxt(String lsBirthDateTxt)
    {
        this.lsBirthDateTxt = lsBirthDateTxt;
    }


    @SuppressWarnings("unused")
    protected String getLsBirthDateTxt()
    {
        return lsBirthDateTxt;
    }


    protected void setLsDeceasedDateTs(Timestamp lsDeceasedDateTs)
    {
        this.lsDeceasedDateTs = lsDeceasedDateTs;
    }


    protected Timestamp getLsDeceasedDateTs()
    {
        return lsDeceasedDateTs;
    }


    protected void setLsDeceasedDateTxt(String lsDeceasedDateTxt)
    {
        this.lsDeceasedDateTxt = lsDeceasedDateTxt;
    }


    @SuppressWarnings("unused")
    protected String getLsDeceasedDateTxt()
    {
        return lsDeceasedDateTxt;
    }


    protected void setLsDeceasedFlag(String lsDeceasedFlag)
    {
        this.lsDeceasedFlag = lsDeceasedFlag;
    }


    protected String getLsDeceasedFlag()
    {
        return lsDeceasedFlag;
    }


    protected void setLsMultipleBirthFlag(String lsMultipleBirthFlag)
    {
        this.lsMultipleBirthFlag = lsMultipleBirthFlag;
    }


    protected String getLsMultipleBirthFlag()
    {
        return lsMultipleBirthFlag;
    }


    protected void setLsMultipleBirthOrderNum(Long lsMultipleBirthOrderNum)
    {
        this.lsMultipleBirthOrderNum = lsMultipleBirthOrderNum;
    }


    protected Long getLsMultipleBirthOrderNum()
    {
        return lsMultipleBirthOrderNum;
    }


    protected void setLsOrganDonorFlag(String lsOrganDonorFlag)
    {
        this.lsOrganDonorFlag = lsOrganDonorFlag;
    }


    protected String getLsOrganDonorFlag()
    {
        return lsOrganDonorFlag;
    }

}
